package com.cockybook.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class JsoupUtil {

    private static   final Logger logger = LoggerFactory.getLogger(JsoupUtil.class);

    public static Document urlGet(String url) throws IOException {
        int i=1;

        while (true){


        try {
            return Jsoup.connect(url)
                    .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
                    .get();

        } catch (IOException e) {
            logger.info(e.getMessage()+" re try count " +i + "URL:   "+url);
            if(i++ == 3){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                }
                throw e;
            }

        }
        }


    }
}
